import React, { Component } from 'react';
// lazy 
// loadable
// 路由懒加载 - （）=> import()  @

function AsyncContainer(importComponent: any) {
  return class AsyncComponent extends Component {
    state = {
      component: null
    }

    componentDidMount() {
      importComponent().then((mod: any) => {
        console.log(mod, 'mod-----mod')
        this.setState({
          component: mod.default
        })
      })
    }

    render() {
      const AsyncCom: any = this.state.component;
      return AsyncCom ? <AsyncCom {...this.props} /> : null
    }
  }
}

export default AsyncContainer